//
//  YHBaseCollectionViewCell.m
//  MoreCoin
//
//  Created by 林宁宁 on 2019/9/17.
//  Copyright © 2019 MoreCoin. All rights reserved.
//

#import "YHBaseCollectionViewCell.h"
#import <YHStyle/UIColor+YHStyle.h>
#import <Masonry/Masonry.h>

@interface YHBaseCollectionViewCell()

@property (retain, nonatomic) UIColor * originColorBackgroud;
@property (retain, nonatomic) UIColor * originColorContent;
@property (retain, nonatomic) UIColor * originColorContentCustom;

@end

@implementation YHBaseCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self yh_nibConfig];
}

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        [self defaultStyle];
        [self yh_commonInit];
    }
    return self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if(self){
        [self defaultStyle];
        [self yh_commonInit];
    }
    return self;
}

-(void)setHighlighted:(BOOL)highlighted{
        
    if(!self.originColorBackgroud){
        self.originColorBackgroud = self.backgroundColor;
    }
    if(!self.originColorContent){
        self.originColorContent = self.contentView.backgroundColor;
    }
    if(!self.originColorContentCustom){
        self.originColorContentCustom = self.cellContent.backgroundColor;
    }
    
    if(self.originColorBackgroud &&
       ![self.originColorBackgroud yh_isEqualToColor:[UIColor clearColor]]){
        if(highlighted){
            self.backgroundColor = [self.originColorBackgroud darkerColor:0.9];
        }else{
            self.backgroundColor = self.originColorBackgroud;
        }
    }
    if(self.originColorContent &&
       ![self.originColorContent yh_isEqualToColor:[UIColor clearColor]]){
        if(highlighted){
            self.contentView.backgroundColor = [self.originColorContent darkerColor:0.9];
        }else{
            self.contentView.backgroundColor = self.originColorContent;
        }
    }
    if(self.originColorContentCustom &&
       ![self.originColorContentCustom yh_isEqualToColor:[UIColor clearColor]]){
        if(highlighted){
            self.cellContent.backgroundColor = [self.originColorContentCustom darkerColor:0.9];
        }else{
            self.cellContent.backgroundColor = self.originColorContentCustom;
        }
    }
}

- (void)defaultStyle{
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
}

- (void)yh_commonInit{};
- (void)yh_nibConfig{}

- (void)configCellWithData:(id)data indexPath:(NSIndexPath *)indexP{};

+ (NSString *)cellIndentify{
    return [NSString stringWithFormat:@"collectionViewReuseIndentify_%@",NSStringFromClass(self)];
}


@end
